
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.hre.db.dao.EmpEducationDAO;
import com.edu.hre.db.dao.EmpSkillDAO;
import com.edu.hre.db.dto.HreEmpEducation;
import com.edu.hre.db.dto.HreEmpSkill;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

/**
 * Servlet implementation class SkillServlet
 */
public class SkillServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SkillServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int employeeNumber = Integer.parseInt(request
				.getParameter("emp_number"));
		List<HreEmpSkill> skill = new EmpSkillDAO()
				.getSkillByEmployeeId(employeeNumber);
		Gson gson = new Gson();
		JsonObject myObj = new JsonObject();
		myObj.addProperty("success", true);
		myObj.add("skill", gson.toJsonTree(skill));
		myObj.addProperty("totalCount", skill.size());
		response.setContentType("text/html");
		response.getWriter().println(myObj.toString());
		response.getWriter().close();
	}

}
